﻿using AutoMapper;
using MediatR;
using PublicClass.Shift;
using S.Produce.Api.Application.Commands.ShiftCommands;
using S.Produce.Domains;
using S.Produce.Infrastructure;

namespace S.Produce.Api.Application.CommandHandlers.ShiftCommandHandlers
{
    public class ShiftCreateCommandHandler : IRequestHandler<ShiftCreateCommand, int>
    {
        private readonly IRepository<ShiftDorm> _shiftdorm;
        private readonly IMapper mapper;

        public ShiftCreateCommandHandler(IRepository<ShiftDorm> shiftdorm, IMapper mapper)
        {
            _shiftdorm = shiftdorm;
            this.mapper = mapper;
        }

        public async Task<int> Handle(ShiftCreateCommand request, CancellationToken cancellationToken)
        {
            request.CreateDate = DateTime.Now;
            request.CreateBy = "张三";
            request.UpdateDate = null;
            request.UpdateBy = null;
            var res = await _shiftdorm.CreateAsync(mapper.Map<ShiftDorm>(request));
            return res;
        }
    }
}
